<?php
  require_once 'database.php';
  echo "这里是主页";
  session_start();
  if ($_SESSION['username']==true) {
      echo "";
  }else{
      echo "";
      header("Refresh:1;url=login.html");
  }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生列表</title>
    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" 
    integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <style>
      .table{
        margin:20px 20px;
      }
    </style>
</head>
<body>
<table class="table">
  <thead>
    <tr>
      <th scope="col">账号</th>
      <th scope="col">密码</th>
      <th scope="col">电话</th>
      <th scope="col">地址</th>
      <th scope="col">性别</th>
      <th scope="col">操作</th>
    </tr>
  </thead>
  <tbody>
    <?php
      //查询数据
      $sql="select * from stu";
      //执行sql
      $result=$conn->query($sql);

    ?>
      <?php
        while($row=$result->fetch_assoc()){
      ?>
        <tr>
          <td><?php echo $row["username"]?></td>
          <td><?php echo $row["password"]?></td>
          <td><?php echo $row["tel"]?></td>
          <td><?php echo $row["address"]?></td>
          <td><?php echo $row["sex"]?></td>
          <td>
            <a href="edit.php?id=<?php echo $row['id']?>">编辑</a>
            <a href="del.php?id=<?php echo $row['id']?>">删除</a>
          </td>
        </tr>
      <?php
        }
      ?>
  </tbody>
  <a href="add.html" style="padding:20px;">添加学生信息</a>
  <a href="logout.php" style="position:absolute;right:80px;">退出登录</a>
</table>
</body>
</html>